﻿/**
 ******************************************************************************
 * @file    priority_queue.h
 * @author  LiaoQingfu
 * @version V1.0.1
 * @date    2017-03-07
 * @brief   优先级队列头文件, 该版本排序部分的功能已经被阉割，所以这个版本实际上也只是普通的队列.
 * ******************************************************************************
 */
#ifndef __PRIORITY_QUEUEL_H__
#define __PRIORITY_QUEUEL_H__
#include <pthread.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct link_node
{
    void *item;
    struct link_node *link;  //指针域——后继指针
}link_node_t;

typedef struct
{
    link_node_t *front; 		//队头指针，即链头指针
    int (*sortCallBack)(void *newItem, void *curItem);
    int  size;
    pthread_mutex_t  mutex;
}priority_queue_t;

//优先级队列初始化

priority_queue_t *priority_queue_init();
void priority_queue_deinit(priority_queue_t *queue);
int priority_queue_push(priority_queue_t *queue, void *item);        //将新元素x插入到队尾
void* priority_queue_get_head(priority_queue_t *queue) ;         		//取队列头元素,但不删除
void* priority_queue_pop_head(priority_queue_t *queue);				//取队列头元素并将其从队列中删除
int priority_queue_is_empty(priority_queue_t *queue);           		//判断队列是否为空
int priority_queue_size(priority_queue_t *queue);            		//求优先级队列中元素个数
int priority_queue_delete_item(priority_queue_t *queue, void *spec_item);
int priority_queue_find(priority_queue_t *queue, void *item);
void priority_queue_traverse(priority_queue_t *queue, void *user_data, void (*traverse_callback)(void *item, void *user_data));

#ifdef __cplusplus
}
#endif

#endif
